<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">










<html>
  <head>
    <title>log4php - 
        Log4php - Quick Setup Guide</title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
          <meta name="author" content="
        Marco Vassura" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                  <a href="http://logging.apache.org/" id="bannerLeft">
    
                                            <img src="images/ls-logo.jpg" alt="" />
    
            </a>
                    <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
            <div class="xleft">
        Last Published: 07/30/2007
                          |   
          <a href="http://www.apache.org/">Apache</a>
              &gt;
      
          <a href="http://incubator.apache.org/">Incubator</a>
              &gt;
      
          log4php
                        </div>
            <div class="xright">      
  

  
    
  
  
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
                   <h5>Get log4php</h5>
        <ul>
              
    <li class="none">
              <a href="download.html">Download</a>
        </li>
              
    <li class="none">
              <a href="changes-report.html">Changes</a>
        </li>
              
    <li class="none">
              <a href="license.html">License</a>
        </li>
          </ul>
          <h5>About log4php</h5>
        <ul>
              
    <li class="none">
              <a href="index.html">What is it?</a>
        </li>
              
    <li class="none">
              <strong>Quick start</strong>
        </li>
              
    <li class="none">
              <a href="usage.html">Usage</a>
        </li>
              
    <li class="none">
              <a href="roadmap.html">Roadmap</a>
        </li>
              
    <li class="none">
              <a href="apidocs/index.html">PHPDoc</a>
        </li>
          </ul>
          <h5>Community</h5>
        <ul>
              
    <li class="none">
              <a href="mail-lists.html">Mailing Lists</a>
        </li>
              
    <li class="none">
              <a href="issue-tracking.html">Issue Tracking</a>
        </li>
          </ul>
          <h5>Development</h5>
        <ul>
              
    <li class="none">
              <a href="source-repository.html">Repository</a>
        </li>
          </ul>
          <h5>Apache</h5>
        <ul>
              
    <li class="none">
              <a href="http://www.apache.org">Home</a>
        </li>
              
    <li class="none">
              <a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a>
        </li>
              
    <li class="none">
              <a href="http://www.apache.org/foundation/thanks.html">Thanks</a>
        </li>
              
    <li class="none">
              <a href="http://www.apachecon.com">Conferences</a>
        </li>
          </ul>
                                       <a href="http://maven.apache.org/" title="Built by Maven" id="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        
    
    <meta name="keywords" content="php, java, logging, tracing, component, framework, API, log4php"></meta>
    
        <a name="Quick Setup Guide"></a><div class="section"><h2>Quick Setup Guide</h2>
            <a name="The package tree"></a><div class="section"><h3>The package tree</h3>
                <p>After unpacking the distribution file the following source tree will be created:</p>
                <pre>
log4php-{version}
    +---docs
    |   +---api
    |   qsg.html (this file)
    |       ...
    \---src
        +---log4php
        |   +---appenders
        |   +---config
        |   +---helpers
        |   +---layouts
        |   +---or
        |   +---spi
        |   +---varia
        |   \---xml
        \---tests
            ...
                </pre>
            </div>
            
            <a name="Installation"></a><div class="section"><h3>Installation</h3>
                <p>
                    Copy the &quot;<code>log4php-{version}/src/log4php</code>&quot; directory in a place accessible by PHP 
                    (called in this document <code>{LOG4PHP-ROOT}</code>)
                    and  that's all! Log4php is installed. 
                    Optionally the <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_DIR">LOG4PHP_DIR</a> 
                    constant can be defined to point to <code>{LOG4PHP-ROOT}</code>.
                </p>
            </div>
            
            <a name="How to use"></a><div class="section"><h3>How to use</h3>
                <p>
                    Three steps are required to use log4php:
                </p>
                <ol type="1">
                    <li>
                        Create a configuration file (can be an &quot;.ini&quot;-type or xml file)
                        that will configure the log4php loggers hierarchy tree.<br></br>
                        See the <code>tests/*/configs</code> directories for examples.<br></br>
                        See <code>log4php.dtd</code> for xml elements reference.<br></br>
                        Finally, take a look at the original log4j manual for more examples.
                    </li>
                    <li>
                        (Optional) Define the <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_CONFIGURATION"><code>LOG4PHP_CONFIGURATION</code></a> 
                        constant to point to the configuration above. 
                    </li>
                    <li>
                        (Optional) Define the <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_CONFIGURATOR_CLASS"><code>LOG4PHP_CONFIGURATOR_CLASS</code></a>
                        constant to point to a configuration class file.
                    </li>
                    <li>
                        Include the '<a href="apidocs/log4php/LoggerManager.html"><code>LoggerManager.php</code></a>' 
                        class file in your php scripts.
                    </li>
                </ol>
                
                    Once the '<a href="apidocs/log4php/LoggerManager.html">LoggerManager</a>' is included,
                    it will start the <a href="apidocs/log4php/_LoggerManager.php.html#functionLoggerManagerDefaultInit">default init procedure</a> 
                    that can be parameterized by the previously defined 
                    <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_DEFAULT_INIT_OVERRIDE"><code>LOG4PHP_DEFAULT_INIT_OVERRIDE</code></a>, 
                    <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_CONFIGURATION"><code>LOG4PHP_CONFIGURATION</code></a> and 
                    <a href="apidocs/log4php/_LoggerManager.php.html#defineLOG4PHP_CONFIGURATOR_CLASS"><code>LOG4PHP_CONFIGURATOR_CLASS</code></a>
                    constants.
                
                Here is how to use <code>log4php</code> in user PHP code:
                <pre>
&lt;?php
/*
    Set LOG4PHP_* constants here 
*/

require_once(LOG4PHP_DIR . '/LoggerManager.php');

/*
    In a class
*/
class Log4phpTest {
    /*
        Your public and private vars
    */
    var $_logger;
    
    function Log4phpTest()
    {
        $this-&gt;_logger =&amp; LoggerManager::getLogger('Log4phpTest');
        $this-&gt;_logger-&gt;debug('Hello!');
    }

}

function Log4phpTestFunction()
{
    $logger =&amp; LoggerManager::getLogger('Log4phpTestFunction');
    $logger-&gt;debug('Hello again!');    
}

/*
    Your PHP code
*/

//Safely close all appenders with...

LoggerManager::shutdown();

?&gt;
                </pre>
            </div>
        </div>
    

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2007
    
          Apache Software Foundation
          
  

  
    
  
  
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
